package com.ly.demo.entity;

import com.ly.demo.annotation.IEnum.KafkaEventEnum;
import lombok.Data;

/**
 * @Author liuyang
 * @Date 2024/3/15 17:50
 **/
@Data
public class KafkaVo<T> {
    private String event;
    private T data;
    private String msg;
    private boolean success;

    public static KafkaVo instance() {
        return new KafkaVo();
    }

    public KafkaVo data(String event, T data, String msg, boolean success) {
        this.event = event;
        this.data = data;
        this.msg = msg;
        this.success = success;
        return this;
    }

    public static KafkaVo ok(String event, Object data, String msg) {
        return instance().data(event, data, msg, true);
    }

    public static KafkaVo fail(String event, Object data, String msg) {
        return instance().data(event, data, msg, false);
    }

    public static KafkaVo ok(KafkaEventEnum eventEnum, Object data) {
        return ok(eventEnum.getEvent(), data, eventEnum.getDesc());
    }

}
